﻿using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace QA.TFS.Utils
{
    class StringReplacer
    {

        public static string cleanForProcedureCall(string statement)
        {
            string result = "";
            result = statement.Replace("EXEC", "");
            if (result.Contains("@"))
                result = result.Substring(0, result.IndexOf("@") - 1);
            return result.Trim();
        }

        public static Dictionary<string, string> extractFromSource(string source)
        {
            Dictionary<string, string> result = new Dictionary<string, string>();
            Regex regExStatement = new Regex(@"(\w*)(\@([a-zA-Z]+)[\s]?\=[\s]?(([a-zA-Z]*[0-9]*\s*)+)[\,]*)+");
            try
            {
                MatchCollection rs = regExStatement.Matches(source);
                foreach (Match item in rs)
                {
                    if (item.Groups.Count == 6)
                        result.Add(item.Groups[3].Value, item.Groups[4].Value);
                }
                return result;
            }
            catch (Exception e)
            {
                throw e;
            }
        }

    }
}
